A Debian Buster image for Raspberry Pi 3 to learn or teach coding with JupyterHub (python, JS), Snap!BYOB (bloc-programming), MRAA and UPM (maker world)

This article offers a fast method to build and install the Debian Buster (Linux Debian 10) distribution on a Raspberry Pi3 nano-computer and also to add the softwares needed to learn or teach coding. It enables also to deploy a "weather and climate" project (with Weewx,MRAA and UPM) or any project using the Raspberry Pi GPIO bus and effector or LED sensors to teach and learn how to code in a real life situation. This is not a generic documentation but a description of a process that has been implemented, it includes personal choices that can be modified. It thus allows one to realize an ad-hoc installation, corresponding to one's specific needs at some point. This installation is based on a work leaded by drtyhlpr which can be read here : rpy23-gen-image. As the Raspberry Pi described in this article runs on a Linux Debian system this article assumes that the host machine interacting with the Raspberry Pi works under a Debian operating system (no need for advanced knowledge in linux administration to follow this article). As an important part of the interaction is performed via a remote terminal or a terminal server, this method can also be executed from other computer environments.

Motivations

The "Météo et Climat tremplin pour l'enseignement des sciences" project (Climate and Meteorology springboard for STEM education) focuses on the instruments for measuring meteorological parameters and exploiting the resulting data, as well as the processing of meteorological and climatological data provided by Météofrance (the French national meteorological service). This interest has merged with the institutional will to teach coding.

This double interest has been realized through the use of nano-computers (Raspberry Pi, Odroĩd, Joule), which enables you to have genuine matchbox-sized multi-core processors at your disposal at an affordable price for an educational institution . These nano-machines allow you to create a measurement data interface working with sensors, to process and display data, or to write programs running on smartphone, tablet or other computer.

Initially simple consumers of technology, the student and his teacher can become actors and producers of resources which can be integrated into the universe of opendata. These nano-machines have direct access to the machine's low-level language (the basic level of the computer) and thus come up as blank pages which require some preliminary work of installation and configuration before we can express our technical scientific or design skills. This step is the core content of this article. In order to help those who simply wait for it to work or to support those who like to know how it works and do it themselves, we propose two different approaches:

  1. For those who don't have much time to get into the details of the creation of the "image" (a file to download onto an SD card to boot the Raspberry Pi more easily), an "image" containing all the necessary tools for a Weather project is available for download. To install it directly on a micro-SD and operate the Raspberry Pi; Go to chapter 2 at the beginning of the article.

  2. For those who want to completely master the content of the machine they are going to use with their students, the process of image creation is fully described and should be reproduced (provided you have some numerical skills and a machine running under a free operating system; this work was done with a Debian buster machine but any other linux distribution may be appropriate). The rest of the document describes the method which was used to create the image proposed online that can be followed to self build the image. This method can be adapted and modified to meet the needs of a project or to fit the pedagogical constraints of a given teaching.

Downloads

  1. Compressed Debian 10 image for Raspberry Pi
  2. Configuration file for bmaptools users

Thanks to

Carole Larose, Éric le Jan and Charles-Henri Eyraud for proofreading, advice and remarks. Charles-Henri for his contribution to the image installation on an other OS than Linux. Adèle for translation and help with english language Myriam for cross reading and support.


Contents

  1. Some strategic choices

  2. Install the image on a microSD card and immediately start the Raspberry Pi3

    a. Micro-SD preparation and construction

    b. First start-up of the Raspberry Pi under the newly installed system

    c. Using Remote RaspPi

    d. Activating the camera

    e. Update: mraa system and upm

  3. How to build a Debian Buster image

    a. Prepare the third-party computer used to build the image

    b. Image construction

    c. Image finishing state

  4. Manual construction of Debian packages specifically used for the "Tremplin" project

    a. The particular case of the weewx package

    b. Building of the node package

    c. Building of the swig package

    d. Building the package libopenzwave

    e. Building of the mraa package

    f. Building of the upm package

    g. Settings and exploitation of created packages

  5. Installing remote services

    a. Install a remote graphics terminal service

    b. Various configurations for using Python with the GPIO bus

    c. Installation of SNAP! BYOB

    d. Install jupyter and jupyterhub

  6. Image Propagation


* Downloads *

  1. Image Creation Scripts
  2. weewx software
  3. swig software
  4. node v-6.9.1 software This version is required to compile mraa and upm correctly, the work is In progress to use [node v-7.7.0 software] (https://nodejs.org/dist/v7.7.0/node-v7.7.0-linux-armv7l.tar.xz
  5. mraa software
  6. upm software
  7. Client and Terminal Server

1. Some strategic choices

When a customer buys a computer, and even more a smartphone or a tablet, the seller describes in detail the many "turnkey services" offered by the object and the ease with which the user will get them, without ever talking about what this object (which is often a powerful computer) could do if other software choices had been made and often without informing the user of everything the device does without him knowing it.

For the Raspberry Pi you have on the one side a little inert electronic device, on the other side a blank SD memory card, you have to choose among 10 possible operating systems (as of 05/01/2017) what the heart of your machine will be like and what it will do. You are free to rely on any criterion, you can choose the OS that best suits your needs, your project, your desires, your skills and even your concerns about protecting your privacy or your militant positions.

I chose the Debian Buster linux distribution because it enables to compile the tools I need for the "Weather and Climate Springboard project for science teaching" easily, and because the Raspberry Pi3 is equipped with a version 7 arm processor (armv7), which is part of the hardware for which we can find an online official Debian repository (with installation data and softwares everybody can download). The Raspberry Pi3 has an armv8 but the piece of code needed to make it work in 64 bits is still not available (as of 02/01/2017).

It is also possible to choose the kernel version from all those proposed on the site Raspberry Pi Linux git. In this project, the last version was chosen because it corresponded to the Debian Buster kernel version.

2. Install the image on a microSD card and immediately start the Raspberry Pi3

It is necessary for the Raspberry Pi to be operational to have a microSD containing an image capable of booting. The site Raspberry Pi and many forums offer images with special goodies, but to facilitate the work of our colleagues working on the Tremplin project and in order to completely master the contents of the operating system, we realized an image containing the softwares we needed (called "image IFÉ-ENS de Lyon") and made it available on line. This image was conceived disregarding some functions which we didn't need. If you want to install these functions, you can recover the packages and integrate them to the computer (if there are really open packages or if sources are available for these functions : please note that it is not because the Raspberry Pi is a open device that all the software that run on it are open as well...).

The speed of the Raspberry Pi depends heavily on the writing speed of the SD. Class 10 SD cards (with a 10 Mo/s speed) are rather deprecated : it is better to choose a Ultra-high speed SD card (UHS-I or UHS-II), and note that speed often depends on the price. But be careful to check the writing speed, which can be very different from the playback speed.

The installation described here is realized via command line instructions typed from a machine running under linux Debian. As the Raspberry Pi runs by default under linux, this mode of installation is quite spontaneous and also extremely robust. You can find tutorials explaining how to install the image with other OSs which are perfectly compatible with the image proposed here (for instance with Windows). Few tips are given below to install the image from a machine under Windows. If you do not have a Debian machine and want to follow this manual, you can start your computer on a live Debian session. This will not alter your computer and it will restore it to its normal state after the live session. You will find here the method to create a bootable USB key for Debian (a USB key from which a computer can install a different operating system). _ (Any other linux distribution should also work, by the way.) _

To manage the SD card and the installation of the image you will need the softwares gparted, wget, 7z and bmap-tools. For the latter, version 3.2 is required to use the file provided for download. If the computer you are using has another version, 2.5 for example, you will imperatively need to redo the .bmap file by applying this command line :

bmaptool create -o image_name.bmap image_name

The expression image_name correspond to the name of the file provided by the IFE-ENS-de-Lyon on the download site (see below).

2.a Micro-SD preparation and construction

Format SD

under linux It is always better to "clean" your micro SD and format it properly before you start. Before formatting it could be usefull to write "0" at the beginning of the key.

sudo dd if=/dev/zero /dev/mmcblk0 count=1024

Format your SD in fat32 : the command to do this work under linux is gparted, which offers also a graphical interface. Warning : this command is extremely powerful, make sure to treat your SD only (and especially not any other disk or partition.) Your SD should spontaneously appear under a mmcblk? type of name.

Before formatting it could be usefull to write "0" at the beginning of the key.

sudo dd if=/dev/zero /dev/mmcblk0 count=1024
sudo gparted

Use the gparted commands in the drop-down menus delete partitions if any, write a partition table then select the entire surface and add a single primary partition to fat32. Execute the operation and exit gparted.

Format SD with other OS

If you want to use a pre-formatted SD for the RaspberryPi, you'll still need to format it. But since Windows doesn't naturally recognize the ext4 file system, you will have to install on your computer a software which provides this function, for instance ext2fsd (Read Write ext4).

Download the image provided

The image can be found on the mediaserver of the "Tremplin des sciences" project. The YYYY-MM-DD numbers represent the creation date to be set, based on what is available online. To get this number connect with a web browser to Raspberry Pi3 http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianBusterPi3.

To download the image, copy and paste the image's name in the address bar and the download will be launched, or use the linux command wget orcurl.

Raspberry Pi 3

wget http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianBusterPi3/YYYY-MM-DD-debianBusterRpi3.bmap
wget http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianBusterPi3/YYYY-MM-DD-debianBusterRpi3.img.xz

Unzip the downloaded image

The image is in compressed (in xz format) and it is necessary to uncompress it with one of the many unzipping tools available (here we use 7Z):

7z x YYYY-MM-DD-debianBusterRpi3.img.xz

For the .bmap file you must right click on the link and ask "save the target of the link under" to avoid the browser opening the file which in XML readable format.

The decompression provides the image file, after this operation we therefore have:

  • A small first file with the bmap extension which is a configuration file allowing a quick copy with the bmap-tool utility (this file is useless if you use a less powerful operating system not knowing how to exploit the description of the image)
  • The image itself of large size (of the order of 7.5GB) with the extension img

Copy the downloaded image to the microSD

The bmap-tools utility uses the description of the image to be copied to shorten the copy time by not copying the empty blocks and optimizing the size of the copied blocks. Below is a sample copy of the rp3 and rpi2 image.

sudo bmaptool copy --bmap YYYY-MM-DD-debianBusterRpi3.bmap YYYY-MM-DD-debianBusterRpi3.img /dev/mmcblk0

bmaptool: info: block map format version 2.0
bmaptool: info: 921600 blocks of size 4096 (3.5 GiB), mapped 899072 blocks (3.4 GiB or 97.6%)
bmaptool: info: copying image 'YYYY-MM-DD-debianBusterRpi3.img' to block device '
bmaptool: info: 100% copied
bmaptool: info: synchronizing '/ dev / mmcblk0'
bmaptool: info: copying time: 8m 3.9s, copying speed 7.3 MiB / sec

Resize the usable size to the size of the micro SD

The image occupies only the space necessary to contain the system and the basic files (with a little margin for the stunned), it is desirable as soon as possible to increase the size of the partition to the total size of the MicroSD to have the place to put other software or data. Depending on your habits and your mastery you can create several partitions at this time if you want to create several partitions (Do not commit to creating more partitions if you do not know how to do it because it will also be necessary to modify the configuration file of the system /etc/fstab so that it works). To resize the partition two procedures are possible: one using gparted the other applicable after the first start (see next chapter).

Using the third-party computer

Eject and plud again the microSD before starting the size modification, reuse gparted always with the same caution recommendations.

sudo gparted

Exit gparted eject the microSD and install it on the Raspberry Pi, you now have an operational Raspberry Pi ready for the weather and programming! To use it, you have to slide the SD into the slot, connect the Raspberry Pi to the network and a micro-USB power supply and you will be able to go! This connection is enough to be operational but for the first time especially if one is not accustomed to the linux command line it is desirable to also connect a screen a keyboard and a mouse.... and we find ourselves in front of a true computer (See below).

Reconfiguration of the wired network

It is important that the users belong to the netdev group in order to modify the network configuration. To do this, modify the /etc/group file of the newly copied card, (not putting users in this group is a method to limit their access on a specific Internet network). The manipulation can be done directly on the card mounted on the third-party computer (without installing it on the Raspberry Pi) modify the line netdev like this netdev: x: 108: ens-ife to add ens-ifeuser, this work is already done for Pre-installed users ens-ife, localadm, callisto, moon...

In order to register on the wired network a file 50-wired.network has been saved in the /etc/systemd/network folder to catch the wired network on a DHCP environment with whatever available interface :


It is also imperative to identify the name of the wired interface And enter it in the manager-settings.conf file, to get the name hit :

ip address
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
    2:enxb827eb3c732f: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether b8:27:eb:3c:73:2f brd ff:ff:ff:ff:ff:ff
    3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:69:26:7a brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.14/24 brd 10.0.1.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:fe69:267a/64 scope link 
       valid_lft forever preferred_lft forever

The name of the interface is here enxb827eb3c732f .

The contents of the manager-settings.conf file should look like this:

[Settings]
backend = external
wireless_interface = wlan0
wired_interface = nom_de_l'interface_filaire
wpa_driver = wext
always_show_wired_interface = True
.../...

2.b First start of the Raspberry Pi on the newly installed system

Install the micro-SD in the connector provided and connect the RPi via the micro-USB connector. With a Raspberry Pi3 it is not necessary to be connected as wired because the image contains the driver of the WIFI which can be activated by default, however for the WIFI connection it is necessary to provide the connection information (name Network and password) before start the Raspberry Pi (see above). It is therefore recommended for the first connection to be connected via the wired network.

Resize the Raspberry Pi storage space

In some cases problems may occur with gparted resized SDs (you will find on the web an abundant literature on performance and Weaknesses of different micro-SDs if you have not chosen a "low-end" SD you should not be concerned with these problems, but ... you never know). In other cases, the older version of gparted does not handle the metadata_csum parameter and can not resize the root partition. In these two cases gparted is unusable and the above solution is unavailable and the solution below using Raspberry Pi itself is mandatory. To avoid usinggparted and the third-party computer it is possible to resize the partition Root directly on the Raspberry Pi running with the new image. To do this once the Raspberry Pi is operational and started use the command

sudo fdisk /dev/mmcblk0
  • Type m to see the list of commands (just for information)
  • Type P to see the list of available partitions, normally there are two
    • a FAT: / dev / mmcblk0p1 * 2048 133119 131072 64M c W95 FAT32 (LBA)
    • a linux: / dev / mmcblk0p2 133120 62517247 62384128 29.8G 83 Linux
  • Then type
    • d then
    • 2 then
    • n then
    • p then
    • 2 then
    • accept the default values that correspond to the actual size available on the SD cards and write N for" Remove signature ",
    • to end type w. Then type sudo reboot then:
sudo resize2fs /dev/mmcblk0p2
sudo reboot

After this second restart, the system root now occupies the entire available space on the SD.

For the first connection it is also desirable / comfortable to have a complete screen / keyboard / mouse environment that makes the Raspberry Pi accessible in an "ordinary" way, the console has been deactivated in this image and therefore does not allow to have Access to the Raspberry Pi via this degraded mode. The screen displays a login prompt:

  • Available logins are
    • ens-ife (set up for team members in case of need for remote support),
    • localadm (local administrator of Raspberry Pi),
    • callisto (owner and launcher of Jupyterhub)
    • moon (regular test user)
  • The start password of the first 2 accounts outside ens-ife is AChanger1 $ (which suggests that it must be changed as soon as possible!) That of moon is guest.

Once in the work environment access the wicd tool to configure the network (see above). We can then continue to work "ordinary" with an active internet connection.

However it is possible to progress in a "less intuitive" but just as effective (command line) way by connecting to the Raspberry Pi via a terminal is what is described below. The only constraint is to have the IP address of the Raspberry Pi to which you connect with the localadm user from a third-party computer using the following commands:

ssh localadm@***.***.***.***
The authenticity of host '***.***.***.*** (***.***.***.***)' can't be established.
ECDSA key fingerprint is SHA256:J4MATvTmHHoSu/Lkz2auFWTJwCgaZTqRBVMIDoshpA4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '***.***.***.***' (ECDSA) to the list of known hosts.
localadm@***.***.***.***'s password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Setting up basic comfort

The initial users ens-ife and localadm are privileged users. * It is dangerous to work on the privileged user * while it is possible and quick to create as many users as necessary (all ordinary users will have to be created with the method below). Create a user and continue in the space of this user, it is possible to work as a user moon, the ompte was preconfigured by default.

sudo adduser myUser

Answer questions using no accented characters or special characters (except for the password). It is also useful to place this user in a certain number of groups in order to facilitate daily operation:

  • The i2c group to access the i2c bus and the sensors it carries
  • The gpio group to access the gpio bus
  • Netdev group to access the network settings.
  • Jupyter group to access the services of jupyterhub
sudo adduser myUser netdev
sudo adduser myUser gpio
sudo adduser myUser i2c
sudo adduser myUser jupyter

2.c Using the RaspPi Remote Graphically

The use of the command line is not necessarily easy to access for many users and it is useful to provide a remote graphical interface for users who do not know or can not adapt to the command line . The solution involves setting up a terminal server on the Raspberry Pi associated with a client that displays the Raspberry Pi remote screen. The terminal server on the Raspberry Pi is installed by default and the service is set up but not enabled. This service is useful only if you want to connect via a remote graphics environment; Otherwise it is desirable to keep it deactivated (see below). For an unknown reason even when activated, the service refuses to start automatically to the boot so it must be launched by hand. To do this connect remotely with a console knowing the IP address of the Raspberry Pi and issue the command:

ssh localadm@xxx.xxxxxx.xxx sudo --stdin service vncserver start

The server starts and provides online access. To connect to this graphics terminal server provide the customer with the following information:

  • Login: callisto
  • Password: the one that was delivered the first time the server started
  • Address xxx.xxx.xxx.xxx:1
  • Port 5901

Raspberry Pi 3 In a Terminal Server

On this figure remmina was used.

To turn off the remote service

ssh localadm@xxx.xxxxxx.xxx sudo --stdin service vncserver stop

If the terminal server is not yet activated (it is proposed as a service in the proposed image but not necessarily activated by default [this point is under discussion because of the security consequences]), To run it and retrieve a graphic mode you need a password that is created at the first launch of vncserver as in the example below, we use (the password is preserved and does not perish, you need a command to change him) :

localadm@raspife3:~$ vncserver

You will require a password to access your desktops.

Password: 
Verify:   
Would you like to enter a view-only password (y/n)? n

New 'X' desktop is raspife3:1

Creating default startup script /home/ens-ife/.vnc/xstartup
Starting applications specified in /home/ens-ife/.vnc/xstartup
Log file is /home/ens-ife/.vnc/raspife3:1.log

ens-ife@raspife3:~$ 

It is then possible to display the screen of the Raspberry Pi on the screen of any computer using a terminal server client, for example the opensource client Tightvncserver.

Setting up a VNC broadcast on port 5901

The systematic solution of the service consumes resources and is set up by default. A less elegant way to get a graphical display is that each user * myUser * can launch a terminal server to his / her name to do this by adding to the /etc/rc.local file for each user " myUser " the line next :

su myUser -c / usr / bin / vncserver

As in the previous case at the first launch of vncserver by the user myUser it is necessary to choose the password of the terminal server or have fixed it in advance with the command:

vncpasswd

Executed as myUser.

Whether using the default terminal server or a custom server it is desirable before terminating the Raspberry Pi to terminate the terminal servers either by terminating the service or by using the following command for each user:

vncserver -kill: 1

Finding the MAC address or recognizing the WIFI interface

To implement this solution we must know the MAC address of its WIFI interface for this we use the ip instruction on the Raspberry Pi:

ip addr show

Which provides in the event that the Raspberry Pi has taken IP 192.169.11.120:

3: wlan0: <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    Link / ether **:**:**:**:**:** brd ff:ff:ff:ff:ff:ff
    Inet 192.169.11.120/24 brd 192.169.11.255 scope global dynamic wlan0
       Valid_lft 9165sec preferred_lft 9165sec
    Inet6 $$$$ :: $$$$: $$$$: $$$$: $$$$ / 64 scope link
       Valid_lft forever preferred_lft forever

Where * *:**:**:** is the unique MAC address of the interface. You must have the machine that will serve as a client for the terminal on the same network and look for the address of the Raspberry Pi card (you need administrative rights):

sudo nmap -sP -n 192.169.11.0/24 | Grep -e **: **: **: **: **: ** -B 2

Caution some network administrators do not like (at all, at all) that a lambda user uses this privileged command and is deemed 598/5000 Aggressive because it allows to obtain information on the network, in this case you will not get any answer or you will see disembarking in the office the security of the establishment .... However if you do not repeat it a hundred of Once you have recovered your IP you are in a known situation and you can connect from a terminal:

ssh 92.169.11.120 vncpasswd (give a session password ) Vncserver

Then a VNC client and the screen of the Raspberry Pi appears on your machine ....

2.d Updates: System, mraa, and upm

This keeps the operating system consistent.

System Update

Depending on the time between the construction of the image and the installation, this may take time and consume bandwidth, only when you have sufficient time and fast connection.

apt-get update
apt-get upgrade
apt-get dist-upgrade

Updating mraa and upm

Mraa and upm are opensources libraries supported by Intel and an important and very active community, it is possible that the version compiled in the image is not sufficiently up to date (for example a significant contribution was made on the code of a Sensor you are interested in) and in this case it is necessary to retrieve the latest version online and compile it. This is facilitated by the structure in place. To update mraa two situations are possible:

If the mraa and upm repositories are already cloned (which is the case in the ENS-IFÉ image)

In this case there is a Software / IoT / mraa and Software / iOt / upm directory in the storage space of the default administrator (localadm) in this case:

  • Update repositories from the online resource
  • Enter the build folder
  • prepare compilation with the cmake instruction
  • compiler installer
  • the new version is available!

Attention in the oldest images the build directory is named Build instead of build the rest of the procedure remains the same.

cd ~/Logiciels/IoT/
cd mraa/
git pull
.../...
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make -j4
sudo make install
cd ../../upm
git pull
.../...
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make -j4
sudo make install

Usually the compilation happens without problems but sometimes insufficiently verified contributions cause errors that are corrected quickly:

  • Either you can wait for correction,
  • Either the affected driver does not interest you and you remove it from compilation with the command:
rm -r ../src/nameOfDeletedDriver
  • Either you recognize the error in the code and you can correct the source!

If the deposits are not present in the image (other than that of ENS-IFÉ for example)

You have to download them: - Choose a directory that will receive the sources and clone the mraa and upm repositories inside - create the build folder inside the mraa and upm folder and then enter this folder - prepare compilation with the cmake instruction - compiler installer - the new version is available!

mkdir -p Logiciels/IoT
cd Logiciels/IoT
git clone https://github.com/intel-iot-devkit/mraa.git
mkdir -p mraa/build
git clone https://github.com/intel-iot-devkit/mraa.git
mkdir -p  upm/build
cd mraa/build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make
sudo make install
cd ../../upm/build
cmake -DWERROR=off -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make
sudo make install

In October 2016, a change to the structure occurred at the request of the users, all the python modules in the upm library were grouped together in an upm directory. This implies that the code is no longer imported directly. In programs older than this date, it is appropriate to replace

import pyupm_driveName

by

import upm
from upm import pyupm_DriverName as myName

You can then use myName later which will lighten the notation.


The following chapters deal with the technique of constructing the ENS-IFÉ image which is proposed online.

Accompanying the use of the Raspberry Pi to learn the coding and remote control of weather sensors can be found in the article Learning how to code with weather in a web environment (LEDs, sensors, display ...)


3. How to Build a Debian Buster Image

This section describes how to build a Debian Buster image on a Raspberry Pi3 yourself. The rest of this article describes the work actually carried out to arrive at the image proposed at the end of the article and put online at the following addresses:

  • [image Raspberry Pi 3] (http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianBusterPi3 /),

The construction of the image is based on a set of free scripts initiated and managed by drtyhlpr and deposited on the GitHub opensource forge at: rpi23-gen-image. These scripts ensure all the work of downloading compilation and formatting of the image. Informed users will be able to directly use this resource according to their needs.

3.a Preparing the third-party computer to build the image

In order to speed up the creation process, we use another machine than the target Raspberry Pi to build the image, the following packages must be installed on the host machine: debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc. Test the presence of these packages and install them if necessary:

for i in debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc crossbuild-essential-armhf gparted wget p7zip-full; do dpkg -l $i; done

Any missing package will be flagged by:

dpkg-query: no package matches ...

It must be installed

sudo apt-get install debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc crossbuild-essential-armhf gparted wget p7zip-full

I have added crossbuild-essential-armhf gparted wget 7z packages which are also useful in the procedure below. It is also possible to create an armhf (chroot) development environment independent of the image creation process with the following commands:

qemu-debootstrap --arch = armhf sid / chroots / sid-armhf ftp://ftp.debian.org/debian/
chroot / chroots / sid-armhf
mount -t proc proc / proc

It can be used to produce packages or compile software more quickly using the power of a third-party computer. It installs on the emulation the sources and software needed to compile the desired programs.

Download the kernel to build the image (optional)

It is possible to choose the version of the kernel that we want to use for our image because the domain raspberrypi on git offers several. We will download version 4.X:

mkdir Kernel
cd Kernel
git clone -b rpi-4.X.y --single-branch https://github.com/raspberrypi/linux.git

The source code of the kernel decompresses into a folder named linux, we'll see how to use it later.

Download scripts rpi23-gen-image

Clone the GitHub repository in enough space to hold the software and the future image (from 1.5 GB to more than 3.5 GB)

git clone https://github.com/drtyhlpr/rpi23-gen-image.git

This action creates the rpi23-gen-image directory that contains all of the scripts and the main executable script. The templates folder contains a list of specific configurations that will be applied to our image

Itzawisis. €: ls -al
Total 852
drwxr-xr-x 8 vidal vidal 4096 Feb. 24 01:31 ./
drwxr-xr-x 9 vidal vidal 4096 Feb. 8 08:41 ../
drwxr-xr-x 2 vidal vidal 4096 Feb. 23 02:45 bootstrap.d /
-rw-r-r- 1 vidal vidal 714143 dec. 11 21:46 createrpi3.txt
drwxr-xr-x 15 vidal vidal 4096 Sep 7 16:02 files /
-rw-r-r- 1 vidal vidal 2153 Feb. 23 02:45 functions.sh
drwxr-xr-x 8 vidal vidal 4096 Feb. 23 19:37 .git /
-rw-r-r- 1 vidal vidal 43 Sep 7 16:02 .gitignore
drwxr-xr-x 3 vidal vidal 4096 Nov 24 23:49 images /
-rw-r-r- 1 vidal vidal 18092 Sep 7 16:02 LICENSE
drwxr-xr-x 2 vidal vidal 4096 dec. 4 18:46 packages /
-rw-r-r- 1 vidal vidal 23740 Feb. 23 02:45 README.md
-rwxr-xr-x 1 vidal vidal 19550 Feb. 23 02:45 rpi23-gen-image.sh *
-rwxr-xr-x 1 vidal vidal 18053 dec. 11 20:23 rpi3-gen-image.sh *
drwxr-xr-x 2 vidal vidal 4096 feb. 24 02:12 templates /

It is necessary to set a certain number of variables to produce an image corresponding to our needs. To simplify this action, it is proposed to group these parameters inside a file that is called by the main script. This makes it possible to simply reproduce the generation of an image. Templates is provided in the templates directory and you can simply add its own configuration file to this directory and it can be used by the creation process.

itzawisis. €: ls -al templates 
-rw-r--r-- 1 vidal vidal 2478 nov.   1 20:45 raspife2-stretch
-rw-r--r-- 1 vidal vidal 2964 nov.   1 20:45 raspife3-buster
-rw-r--r-- 1 vidal vidal  102 nov.   1 20:45 raspife3-jessie
-rw-r--r-- 1 vidal vidal 2856 nov.   1 20:45 raspife3-stretch
-rw-r--r-- 1 vidal vidal 2551 nov.   1 20:45 raspife3W-stretch
-rw-r--r-- 1 vidal vidal 1119 nov.   1 20:45 README.md
-rw-r--r-- 1 vidal vidal   72 juil. 26 10:35 rpi2jessie
-rw-r--r-- 1 vidal vidal   91 juil. 26 10:35 rpi2stretch
-rw-r--r-- 1 vidal vidal  102 juil. 26 10:35 rpi3jessie
-rw-r--r-- 1 vidal vidal  103 juil. 26 10:35 rpi3stretch
-rw-r--r-- 1 vidal vidal  425 nov.   1 20:45 rpi3-stretch-arm64-4.11.y

Creating a configuration file For image raspife3

Raspberry Pi3

The image we are going to create will be named raspife3 to indicate that it is built for a Raspberry Pi3 of the project IFÉ Tremplin for the Teaching of Sciences. The creation parameters have been grouped in the createraspife3 file of the templates folder, this file is reproduced below:

#
# Configuration file raspi3 Buster IFÉ 2017/11/01
#
APT_SERVER=ftp.debian.fr
APT_INCLUDES=""
APT_INCLUDES_LATE="gnupg,firmware-linux-nonfree,firmware-linux,dh-autoreconf,\
gettext,build-essential,git,cmake,libjson-c-dev,unzip,usbutils,\
bison,libboost-all-dev,automake,autoconf,autogen,libtool,libtool-bin,\
pkg-config,checkinstall,menulibre,libnotify-bin,pandoc,\
python3,python3-dev,python3-pypandoc,python3-scipy,python3-tk,python3-pandocfilters,\
python3-geopy,python3-pip,\
python,python-dev,python-pypandoc,python-scipy,python-tk,python-pandocfilters,\
python-geopy,python-pip,python-tk,pandoc,\
python-configobj,python-cheetah,python-imaging,python-serial,python-usb,\
pcre2-utils,libpcre++-dev,libpcre2-dev,libjpeg-dev,i2c-tools,python-smbus,policykit-1,\
pmount,ntpdate,ntp,rsync,\
texlive,texlive-xetex,nginx-extras,ffmpeg,wicd,wicd-gtk,console-data,keyboard-configuration,\
libqtwebkit-dev,libqt5webkit5-dev,\
libudev-dev,libzzip-dev,zlib1g-dev,libcanberra-gtk-module,libnss-myhostname,libfreetype6-dev,libpng16-16,\
nmap,libltdl-dev,dbus-user-session,debian-archive-keyring,\
xutils-dev,lxsession,openbox-lxde-session,lxde,x11proto-randr-dev,lxrandr,\
tightvncserver,geany,geany-plugin-py,firefox-esr,firefox-esr-l10n-fr,jed, terminator"
#ca-certificates-java,icedtea-plugin,icedtea-netx,\
#openjdk-8-jdk,openjdk-8-jre,openjdk-8-jre-headless,\
#openjdk-9-jdk,openjdk-9-jre,openjdk-9-jre-headless"
#----------------------
RPI_MODEL=3 
RELEASE="buster"
RELEASE_ARCH="armhf"
HOSTNAME="raspife3" 
PASSWORD="*****************"
USER_PASSWORD="*****************"
DEFLOCAL="fr_FR.UTF-8" 
TIMEZONE="Europe/Paris"
EXPANDROOT=false
#-----------------------
XKB_MODEL="pc105" 
XKB_LAYOUT="fr" 
XKB_VARIANT="latin9" 
XKB_OPTIONS=""
#------------------------
ENABLE_DHCP=true 
#------------------------
ENABLE_CONSOLE=false
ENABLE_I2C=true
ENABLE_SPI=true
ENABLE_IPV6=true 
ENABLE_SSHD=true 
ENABLE_NONFREE=true 
ENABLE_WIRELESS=true
ENABLE_RSYSLOG=true 
ENABLE_SOUND=true 
ENABLE_HWRANDOM=true 
ENABLE_MINGPU=true 
ENABLE_DBUS=true 
ENABLE_XORG=true
ENABLE_WM="lxdm" 
#------------------------
ENABLE_MINBASE=false
ENABLE_REDUCE=false
ENABLE_UBOOT=false
ENABLE_FBTURBO=true
ENABLE_IPTABLES=false
ENABLE_USER=true 
USER_NAME=ens-ife
ENABLE_ROOT=true 
ENABLE_HARDNET=true
ENABLE_INITRAMFS=true 
ENABLE_IFNAMES=true
#------------------------
ENABLE_ROOT_SSH=false  
SSH_LIMIT_USERS=false
SSH_ROOT_PUB_KEY="*********************************"
SSH_USER_PUB_KEY="**********************************"
#------------------------
BUILD_KERNEL=true
KERNEL_BRANCH=rpi-4.13.y
KERNEL_REDUCE=false
KERNEL_HEADERS=true
KERNEL_REMOVESRC=true
KERNELSRC_CLEAN=true
KERNELSRC_CONFIG=true
#------------------------
REDUCE_APT=false 
REDUCE_DOC=true 
REDUCE_MAN=false 
REDUCE_HWDB=true
REDUCE_BASH=false 
REDUCE_SSHD=false
REDUCE_LOCALE=false
#-------------------------
ENABLE_CRYPTFS=false
#-------------------------
BASEDIR=/*********/RpiGenImage/Images/${RELEASE}
DATE=`date +%Y-%m-%d`
IMAGE_NAME=${BASEDIR}/${DATE}-rpi${RPI_MODEL}-${RELEASE}

In some configurations it was necessary to delete the preload of the lxde package so that the compilation succeeds, This case as soon as the image is finished (with lxdm) it is necessary to add the package lxde

sudo apt-get install --reinstall lxde

Comments on parameters used

Details on the choice of variables:

  • APT_SERVER is positioned on the host of the machine used, a generic value will be in France ftp.debian.fr
  • APT_INCLUDES provides the list of debian packages that will be used in early bootstrap stages
  • APT_INCLUDES provides the list of debian packages that will be used later, which avoids having to install them later by hand
  • RPI_MODEL provides model (2 or 3) of the Raspberry Pi
  • HOSTNAME the name of the machine
  • PASSWORD the initial password that must be changed to avoid security holes
  • DEFLOCAL specifies that we want an interface in French
  • TIMEZONE defines our geographical position (attention the Raspberry Pi does not have a permanent clock, see the forums on it)
  • ENABLE_WM I choose lxdm for its small size and its low consumption of resources by cons the universe proposed is a bit ... "austere"
  • USER_NAME the first user with administrative rights is here
  • Important KERNELSRC_DIR when present locates the path of the chosen kernel to build this image. By default and without this parameter the kernel is downloaded online from raspberrypi
  • KERNEL_BRANCH enables to choose a particular version of the kernel available at RaspberryPi kernel source

The other variables set a certain number of parameters that are somewhat more technical than can be modified (provided the consequences of such a change are known)

Adding debian packages not included in repositories

For the Weather Climate Springboard project for science education, a number of libraries or functions are required:

  • WEEWX which provides a tool for communicating with a commercial weather station
  • MRAA that provides low-level primitives to interact with the machine's GPIO or I2C bus not currently available as package (non-operational checkinstall), to be compiled on the new distribution
  • UPM which provides drivers for a very large number of sensors or actuators. not currently available as a package (non-operational checkinstall), to be compiled on the new distribution
  • A version of NODE compatible with mraa and upm (6.9.2) that is installed in the standard position (not in the Debian structure)
  • A version of SWIG compatible with mraa and upm that is installed in the standard position (not in the Debian structure)

The situation is complex at the moment due to a lack of maintenance of the javascript part of the swig software. Node evolves very quickly and a number of functions used byswig have been deprecated without being taken into account in swig. It is therefore necessary not to use a Node version higher than 6.9.2. However, a version compatible with node7 has been proposed and is being tested. As soon as it is validated, it will be integrated into the new image.

These software packages must either be compiled from source or loaded from Debian packages built by third parties but not in official repositories. Weewx offers such an online package.

The swig andnode packages must be retrieved from the respective sites and installed because mraa andupm depend on it. In addition, a paragraph in the next chapter is devoted to the creation of these packages if a user wishes to carry out the entire procedure and to create these packages itself from the sources.

3.b Construction of the image

Before building the image it is necessary to create the package directory and place inside all the Debian packages external to the official repositories, whose compatibility with the system that will be created has been verified beforehand. This is not a circular reasoning! It is simply the expression of the fact that creating an image with rpi23gen is a very useful and efficient, but to benefit from it, it must be fed with resources that have been previously tested on a minimal image whose core is identical to that Which will be created (see above the creation of a machine with chroot and qemu). The packages proposed by the Tremplin project have been verified.

To add packages download them from the project drop-down and drop them in the packages directory:

cd rpi23-gen-image
mkdir pakages
cd packages
cp ~ / Downloads / weewx_3.7.1-1_all.deb.

Once the additional packages are available and the executable file contains all the parameters of the previous paragraph, you just need to run the following command:

sudo su
CONFIG_TEMPLATE=raspife3-buster ./rpi23-gen-image.sh

The creation starts automatically and results in the creation of 2 files:

  • The image itself (taking the date and ending with the .img estension)
  • An attachment file to accelerate the copy of the image and considerably reduces the copy time on large microSD cards (taking the date and ending with the .bmap extension)

The bmap file can only be used with the bmap-tools software for which I have not found a windows version. The image is quite ordinary (created with the option sparse which has no influence on its usability) and can be copied with any tool capable of writing bit by bit on one Storage device.

Resize the size of the media that will hold the image

3.c Image Finishes

The end of the preparation of the picture happens on the raspberrypi. Copy the image to a microSD (see above) connect the raspberry to the wired network, look for its IP address and connect with ssh. The key installed during the creation is immediately operational and the first user created has sudo rights and then execute the following commands:

sudo apt-get update
sudo apt-get upgrade
mkdir -p Software/Node
cd Software
mkdir Swig
mkdir IoT
mkdir OpenZWave

For easy access to all the utilities and development environment for education set up around weather [presentation] (http://blog.climatetmeteo.fr/GerardVidal/meteo_jupyter_env.html) and [tools] ( https://github.com/g-vidal/Programmebook) it is desirable to carry out the installations proposed in [Chapter 5] (# head2). The next chapter describes the method used to add the software needed to implement the programs in the encoding environment and must also be installed.

All the installations and improvements described in Chapters 4 and 5 can be carried out without connecting the raspberry to a screen by simply knowing its address on the network and connecting it via ssh. Once the terminal server is installed it is possible to display on the third-party computer the graphical interface of the raspberrypi.

Once the image has been created, put it on an SD formatted in FAT32 (cf chapter 2), mount the SD then perform the following operations (check that the dist-packages directory does not already exist, 'Does not need to create it).

Creating default users and adding them to groups

The automated creation of the image provided a single user for the smooth functioning of the development environment we need the following users:

 - localadm (local administrator of Raspberry Pi),
 - callisto (owner and launcher of Jupyterhub)
 - moon (regular test user)
 - tsuser (user launching vncserver)

Three spacial groups are used in the "Tremplin" image :

  • i2c that lists users of i2c bus
  • gpio that lists users of the gpio resource
  • jupyterhub that lists the users able to launch jupyterhub software

The following commands enable to create the users and put them into the necessary groups.

sudo adduser localadm
sudo adduser localadm sudo
sudo adduser callisto
sudo adduser moon
sudo adduser tsuser
sudo addgroup gpio
sudo addgroup jupyterhub
for i in ens-ife localadm callisto moon; do for j in i2c gpio netdev; do sudo adduser $i $j; done; done
for i in localadm ens-ife callisto; do sudo adduser $i jupyterhub; done
for i in localadm ens-ife callisto; do sudo adduser $i shadow; done

To improve security it is possible (desirable) to remove the login by password from callisto by providing an exclusive login by ssh key.

4. Manual construction of project-specific Debian packages Tremplin

These packages are those which are placed in the package directory of rpi23gen-image in order to directly build a complete image but it goes without saying that these packages that we propose online in the deposit Springboard were built by hand on an identical Raspberry Pi To the target we are targeting in the image, it is this procedure that is described here. The work is done on a Raspberry Pi built with the previous image (the one that is updated online) updated to exactly match the image sui is being created.

The swig and node packages are required for the compilation and operation of mraa and upm, but for the moment these two libraries are not configured to use the node and swig resources organized according to the Debian hierarchy, and mraa and upm often require More advanced versions of swig and node than those of the standard Debian distribution, which is why we offer these repackaged packages that work well with mraa and upm.

4.a The particular case of the weewx package

The weewx package is proposed by its author but a number of libraries are needed to configure weewx. These are: python, python-configobj, python-cheetah, python-imaging, python-serial, python-usb, libpcre2 -dev, these libraries have been added to the initial configuration file and are added by default when building the image.

The weewx package is loaded and installed with the following commands:

wget http://weewx.com/downloads/weewx_3.7.1-1_all.deb
sudo dpkg -i weewx_3.7.1-1_all.deb

Or configured (if it was installed during bootstrap)

sudo dpkg-reconfigure weewx

Provide the parameters corresponding to the station that will be connected via Weewx.

4.b Build / Install Package node

Depending on the distribution and the desired configuration it is possible to download a binary and install it or download the sources to compile and install them.

To use the binary

wget https://nodejs.org/dist/v9.1.0/node-v9.1.0-linux-armv7l.tar.xz
tar xvfJ node-v9.1.0-linux-armv7l.tar.xz
cd node-v9.1.0-linux-armv7l
for i in bin include lib share; do sudo cp -r $i/* /usr/local/$i; done
sudo ln -s /usr/local/bin/node /usr/local/bin/nodejs
sudo npm install -g node-gyp
sudo npm install -g configurable-http-proxy

To compile and install the package from the latest version of the sources, a number of packages are required:

sudo apt-get install build-essential git-core libssl-dev pkg-config libc-ares-dev zlib1g-dev devscripts

The sources are then recovered and compiled.

wget https://nodejs.org/dist/v9.1.0/node-v9.1.0.tar.gz
tar xfvz node-v9.1.0.tar.gz
cd node-v9.1.0
./configure
make
sudo checkinstall

The last command installs the node software and at the same time produces a debian package that was used to build the complete image and that can be reused as much as needed for all Raspberry Pi3 installs.

It is important to check that nodejs, node-gyp and the http proxy provided by node are present because the first two are necessary for Swig and the third necessary for the proper functioning of jupyterhub, it is also possibly used when creating a site Web in node on the Raspberry Pi. If not installed add them with the commands:

sudo npm install -g nodejs
sudo npm install -g node-gyp
sudo npm install -g configurable-http-proxy

4.c Construction of the swig package

The construction of the swig package depends on the packages pcre2-utils,libpcre++-dev,libpcre2-dev which are added to the configuration file for the creation of the image in order to avoid users who wish to construct the image of have to load these dependencies by hand.

In order for swig to produce java executables, java must be available on the machine, so executables, include and node libraries must be linked. Same for javascript (it is therefore imperative to compile node before swig). We use here the version of swig modified by arfoll and updated against the last github version.

git clone https://github.com/g-vidal/swig.git
cd swig
./autogen.sh
./configure
make -j4
sudo make install
sudo checkinstall

The last command installs the swig software and at the same time produces a debian package that was used to build the complete image and that can be reused autanT necessary for all installs of Raspberry Pi3.

4.d Building the package libopenzwave

OpenZWave is not available on arm platforms it is necessary to Compile it from sources. We will use the version of the repository github.

git clone https://github.com/OpenZWave/open-zwave.git
cd open-zwave
make -j4
sudo make install

4.e Construction of the mraa package

This operation can no longer be done in advance for the moment on a Raspberry Pi, it is necessary to build the libraries directly on the newly installed machine. To build the two INTEL packages (MRAA and UPM) it is necessary to have the opkg utilities developed by INTEL for its Yocto distribution. They must be installed from the git repository:

git clone https://github.com/shr-project/opkg-utils.git
make
sudo  make install

the opkg_1.0-1_armhf.deb package is available in The.

MRAA directory is a low-level library allowing interaction with the GPIO bus. It is provided by INTEL under the GPL license on GitHub. Installation is done by cloning from the repository

git clone https://github.com/intel-iot-devkit/mraa.git
cd mraa
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make -j4
sudo make install

You will need to replace the last two lines with

cmake -DIPK = ON -DCMAKE_INSTALL_PREFIX = / usr ..
sudo checkinstall

For Yocto users it is possible to get ipk paste by running Command make package, note that the debian build does not go well in the situation described here (perhaps because of unmet dependencies (to be examined).

The mraa_YYYYMMDD-1_armhf.deb package is no longer manufactured By this method and it is advisable not to use it anymore [see discussion on git] (https://github.com/intel-iot-devkit/mraa/issues/60).

4.f Package build upm

UPM is a library of drivers for a gent number of sensors and microsensors that can be connected to the GPIO bus of the Raspberry Pi.This library can interact directly with a sensor or Effector with simple instructions that are in fact functions masking the complexity of programming an interface. However, it is still possible to pass parameters and to insert calls to these functions in high-level programs such as, for example, the administration of a weather station collecting and transmitting data. This operation can not be done in advance for the moment on a Raspberry Pi, it is necessary to build the libraries directly on the newly installed machine.

git clone https://github.com/intel-iot-devkit/upm.git
cd upm
mkdir build
cd build
cmake -DWERROR=off -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make -j4
sudo make install

When the build of the packages will work again Replace the last three lines with

cmake -DIPK=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make -j4
sudo checkinstall

For Yocto users it is possible to get ipk paste by issuing the make package command, Note that the debian build does not work well in the situation described here (perhaps because of unmet dependencies.) The upm_YYYYMMDD-1_armhf.deb package is no longer manufactured by this method and is (See discussion on git) (https://github.com/intel-iot-devkit/mraa/issues/60).

4.g Settings and operation of created packages and postinstallation

If the 4 debian packages could be created they must be transferred to the host machine that builds the image in the home_rpi23-gen-image / packages directory, they will then automatically be taken into account by the scripts and integrated into the picture. The weewx package will have to be reconfigured according to the parameters of the controlled station and if we do not wish to control a station, we will have to disable weewx which consumes in this case some resources sudo update-rc.d -f weewxd remove.

For a chain production of the image it is necessary to carry out these modifications on an installed image and then to copy the image with modifications in order to propose images directly operational!

Activating the i2c bus

The i2c bus must be activated to be able to use it, everything is prepared but

  • check if the file /lib/modules-load.d/rpi2.conf looks like this :
# bcm2708_rng
snd_bcm2835
i2c-bcm2708
i2c-dev
# rtc-ds1307
spi-bcm2835
  • Add the following two lines and the comments that precede it in the /boot/firmware/config.txt file
# Activate i2c0 i2c1
# I2c0 is used by the Raspberry Pi for other functions and
# Can not be used for direct sensors directly
dtoverlay = i2c0-bcm2708
dtoverlay = i2c1-bcm2708

Enabling non-privileged access to this bus

Acces to the GPIO bus is privileged by default and unpriviliged access must be granted at boot to enable normal users to access to sensors and other resources on the bus. Different solutons exist this one has been tested on our raspberries, some of the instructions might be redundant because amendments have been made at various moments according to face locked situations, simplifying this file (if possible) remains in the todo list. In the /etc/udev/rulesd directory create a 99-com.rules file containing the following:

sudo jed /etc/udev/rules.d/99-com.rules
#ajouter
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio; \
chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio; \
chown -R root:gpio /sys/devices/platform/soc/3f200000.gpio && chmod -R 770 /sys/devices/platform/soc/3f200000.gpio; \
chown -R root:gpio /sys/devices/platform/soc/soc:virtgpio && chmod -R 770 /sys/devices/platform/soc/soc:virtgpio; \
chown -R root:gpio /sys/bus/platform/drivers/pinctrl-bcm2835 && chmod -R 770 /sys/bus/platform/drivers/pinctrl-bcm2835 '"

SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add",
PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; \
chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; \
chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"

Network

The wired interface is unique and is created during the first connection, if the image being installed clones this address propagates the same interface number which is necessarily false. It will be necessary to change it so that the raspi can connect, the actual name of the active interface is obtained by the command:

ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enxb827########: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.202/24 brd 192.168.10.255 scope global enxb827ebcf5ed9
       valid_lft forever preferred_lft forever
    inet6 ####::####:####:####:####/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff

The name of the wired interface is here enxb827######## and it is connected on IP 192.168.10.202 on a network with 255 possible addresses. The wireless interface is wlan0 and is not connected.

Since the migration to systemd it is possible to configure services by adding files in the /etc/systemd hierarchy and for example for the network files in there will replace the traditional /etc/network/interfaces ... Here are some examples used on our raspberries.

To enable a wired interface add file 20-wired.network to /etc/systemd/network with the following contents. "*" wild card is use to match any interface number, this value must be changed by the real id of the interface for security reasons.

[Match]
Name=enx*
Host=raspife3

[Network]
DHCP=yes

[DHCP]
RouteMetric=10

To acquire automatically Wifi interface add file 25-wireless.network to /etc/systemd/network with the following contents.

Match]
Name=wlan0
Host=raspife3

[Network]
DHCP=yes

[DHCP]
RouteMetric=20

It is possible to preconfigure the wifi, to perform this connect your own debian machine to the network that you wish to preinstall into the Raspberry Pi, then whenyou are connected to the desired network go look * Either the file with the name of your network in the /etc/NetworkManager directory and copy this file to the same directory of your Raspberry Pi, at the first start the Raspberry Pi will find the network and can connect to it; * Either the part of the /etc/wicd/network.conf file about the configuration of the network to which you want to connect and copy it into the /etc/wicd/wireless-settings.conf file.

Example of parameters for access to eduroam

[connection]
id=eduroam
uuid=*****************************
type=wifi
permissions=
secondaries=

[wifi]
mac-address=**:**:**:**:**:**
mac-address-blacklist=
mac-address-randomization=0
mode=infrastructure
seen-bssids=
ssid=eduroam

[wifi-security]
auth-alg=open
group=
key-mgmt=wpa-eap
pairwise=
proto=

[802-1x]
altsubject-matches=
eap=peap;
identity=vidal@ens-lyon.fr
password=******************
phase2-altsubject-matches=
phase2-auth=mschapv2

[ipv4]
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

Do not forget to check that the user created by default (for us localadm) belongs to the netdev group, if not to add it otherwise it will not be able to activate or modify the WIFI.

It is possible that the resolver is configured for static use (especially if the wired network is used on the first connection) this is no problem if the machine stays on the same domain using the wired and The wifi. On the other hand, if the machine is able to connect from another network, it is necessary to pass the configuration file of the resolver in dynamic mode to do the following commands (the last one is necessary only if the service is not yet started) :

sudo rm /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo systemctl start systemd-resolved

To finish if the network fails to run automatically on first login or to avoid leaving confidential traces Check the contents of the /etc/wicd/wired-settings.conf and /etc / wicd / wireless-settings.conf files. To reset these files (if you have not chosen to change the configuration manually as suggested above) use the following commands or edit the files and dump them manually.

sudo rm /etc/wicd/wired-settings.conf
sudo rm /etc/wicd/wireless-settings.conf
sudo touch /etc/wicd/wired-settings.conf
sudo touch /etc/wicd/wireless-settings.conf
sudo rm/etc/wicd/*~ 

This mode of operation is of course useful only if your Raspberry Pi acquires its IP automatically via DHCP, it stands to reason that if your Raspberry Pi has a fixed IP no need for this trick. The configuration of a fixed IP is not treated here. (you can get it from archlinux manual

5. Installation of services that can be used remotely

If you want to stop the Raspberry Pi command line install the following package that is excluded from the initial image for technical reasons, it is added in the IF-ENS image of Lyon.

sudo apt-get install systemd-sysv

5.a Installing a Remote Graphics Terminal Service

An elaborate way to achieve this goal is to have a user dedicated to terminal server access, create tsuser and use it:

sudo su tsuser
vncpasswd

The password added by default is the name of the machine raspife3

The file .vnc/xstartup in tsuser home must be changed to look like this :

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
#/etc/X11/Xsession
#Start lxde
/usr/bin/startlxde

The following file vncserver.service is then added to the /etc/systemd/system directory to enable manually start and stop this service or switch it on at startup.

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=tsuser
PAMName=login
PIDFile=/home/tsuser/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -name my-vnc-server -depth 16 -geometry 1024x768 :1
ExecStop=/usr/bin/vncserver -kill :1

[Install]
WantedBy=multi-user.target

To activate at startup type sudo systemctl enable vncserver

Vncserver is then a manipulable service like all the other services of the machine. Do not forget to stop it to avoid permanent broadcast on the network.

By default once the Raspberry Pi is started broadcasting on port 5901 is on (this can be changed later on with sudo systemctl disable vncserver), note that we will find all the servers broacasting on this port... One connects using a VNC client for example xvncviewer or remmina or any other terminal server client!

If you do not intend to use this service (which is activated by default on the ENS image of Lyon IFÉ), you have to deactivate it to avoid consuming resources unnecessarily.

Note that it is possible for any user, at any time to launch a terminal server on the Raspberry Pi with for example the vncserver service described above and to find on another computer a complete working environment provided by the Raspberry Pi.

5.b Miscellaneous configurations for using python with the GPIO bus

The GPIO bus of the Raspberry Pi is not as complete and flexible as that of an Arduino or an Edison, each of these machines has specific properties resulting in different interactions with their GPIO bus. Moreover, since python is often used in training, jupyter and jupyterhub tools can be extremely powerful. This paragraph proposes a number of complementary but useful installations and configurations, which are exploited in the "Tremplin des sciences" proprojest for learning teaching how to code.

Installing virtual environments python

With the distribution buster the two versions python2.7 and python3.6 cohabit without any problem however it can be interesting to develop independently these two universes. It is possible to install virtual environments with the command:

virtualenv -p python2.7 --system-site-packages VirtPython2
virtualenv -p python3.5 --system-site-packages VirtPython3

Installing additional libraries for the GPIO bus

The GPIO bus of the Raspberry Pi is quite particular to the point that there is a library built specifically for the Raspberry Pi. This library can be very useful in some case especially to change the number of pins in PWM mode useful for some programs see Jupyterhub program books, a major drawback is that the library emulates functions and the performances are low, it is advisable to use this lin only when other libs accessing directly the GPIO cannot do the job.

This library is installed via pip (an update of the service packs is done before the installation):

sudo pip install setuptools
sudo pip install wheel --upgrade
sudo pip install Rpi.GPIO
sudo pip3 install setuptools
sudo pip3 install wheel --upgrade
sudo pip3 install Rpi.GPIO

5.c Installation of SNAP! BYOB

SNAP! BYOB is a fork from Scratch with some add ons. It is a JS program with web interface, to install it we just need to dowload it, unzip it and link it on the www root of the Raspberry Pi.

cd /opt
sudo mkdir Snap
cd Snap/
sudo unzip ~/Software/GraphProgram/snap.zip 
sudo ln -s /opt/Snap /var/www/html/snap

Snap is now available at localhost://snap

5.d Installation of jupyter and jupyterhub

This point is also covered in the article [Learning to code with the weather in a web environment (LED, sensors, display ...)] (http://blog.climatetmeteo.fr/GerardVidal/meteo_jupyter_env.html)

sudo pip install jupyter
sudo pip install matplotlib --no-cache-dir #(because of the low memory of the raspi)
sudo pip3 install jupyter
sudo pip3 install jupyterhub
sudo pip3 install git+https://github.com/jupyter/sudospawner
sudo pip3 install matplotlib  --no-cache-dir #(because of the low memory of the raspi)

Installing program booklets in the test user environments assumes here that the starting point is the preferred user ens-ife, repeating the manipulation in the environments of all users who will use the program booklets.

git clone https://github.com/g-vidal/CahierDeProgrammes.git
sudo su moon
git clone https://github.com/g-vidal/CahierDeProgrammes.git
exit

Creating an authentication certificate to protect exchanges between raspberry and clients and configuring jupyterhub.

Security is a crucial step in any exchange over a digital network. Even if your raspberry who is plugged into a TP room behind the firewall of the facility does not seem to be a threat, it could well become one! (This is very fashionable not at this moment in the US series to use Pi Raspberries as digital attack instruments, this is usually fictionalized but actually based on reality).

There is no need for an overriding security policy. On the other hand, it is imperative to put in place a few basic elements of protection which can also serve as a support for an awareness of the numerical risks and Adopt on networks. Authentication allows each group or student (according to the choice of the teacher) to have a protected area of ​​the actions of the rest of the world.

Callisto is by default the user who launches jupyterhub, so to preserve the proposed configuration it is the user callisto who must create a new certificate.

cd ~
mkdir -p Utils/Certificates
cd Utils/Certificates
openssl req -new -newkey rsa:2048 -rand /dev/urandom -nodes -keyout meteojuphub.key -out meteojuphub.csr
# Answer questions with your information
openssl req -new -x509 -days 3652 -key meteojuphub.key -out meteojuphub.pem
# Answer questions with your information

The certificate must be enabled for jupyterhub at the root of the user callisto, in the Jupyterhub directory (it is present by default in the ENS-IFÉ image)

cd
mkdir Jupyterhub
cd ~/Jupyterhub
mkdir config
jupyterhub --generate-config

Edit the jupyterhub_config.py file by uncommenting and entering the 3 lines below:

# c.JupyterHub.spawner_class = 'jupyterhub.spawner.LocalProcessSpawner'
c.JupyterHub.spawner_class = 'sudospawner.SudoSpawner'

## Path to SSL certificate for the public interface of the proxy
#
# Use with ssl_key
c.JupyterHub.ssl_cert = '/home/callisto/Utils/Certificates/meteojuphub.pem'

## Path to SSL key file for the public interface of the proxy
#
# Use with ssl_cert
c.JupyterHub.ssl_key = '/home/callisto/Utils/Certificates/meteojuphub.key'

## set of usernames of admin
#
# If unspecified, the server will be admin.
c.Authenticator.admin_users = set (['loginAdminName', 'othername'])

To run the user who launches jupiterhub must have a number of privileges that are added to the sudoers file:

sudo visudo

Add the following lines to the end of the /etc/sudoers file

# The command (s) the hub can run on behalf of the jupyterhub group users
# Without having a password
# The exact path may differ, depending on how sudospawner was installed
cmnd_Alias ​​JUPYTER_CMD = /usr/local/bin/sudospawner

# Actually give the Hub
# Of the above users without prompting for a password
callisto ALL = (%jupyterhub) NOPASSWD:JUPYTER_CMD

The user must also belong to the jupyterhub group and to the shadow group. If the jupyterhub group has not yet been created, users must be assigned to it.

sudo addgroup jupyterhub
sudo adduser userhublauncher jupyterhub
sudo adduser userhublauncher shadow

Installing the node http proxy if it is not already present:

sudo npm install -g configurable-http-proxy

Without this jupyterhub software can notFunction.

6. Image propagation

You can also move all the folders you want to use later into /home/localadm. If they are in the image you will not have to copy them n times for the n created images. Once all postinstallation manipes are done disassemble the SD then copy its contents on the hard disk (make sure to have the Place required the size of the image may vary)

sudo dd if=/dev/mmcblk0 of=2017-11-12-debianBusterRpi3.img bs=8M conv=sparse count=900
900+0 enregistrements lus
900+0 enregistrements écrits
7549747200 bytes (7,5 GB, 7,0 GiB) copied, 94,4746 s, 79,9 MB/s

I chose to limit the size of my image to 7.5GB So that it can hold in an SD of 8GB, we saw above that the initial effective size of the compiled image was less than 2GB which leaves room for margins even after the installation of the additional packets. Once the image has been copied, it is necessary to redo its bmap:

bmaptool create -o 2017-11-12-debianBusterRpi3.bmap 2017-11-12-debianBusterRpi3.img

The resulting image and its bmap Are now diffuseable but it is desirable to compress the image which if not is a bit .... encombrante

7z a -txz 2017-11-12-debianBusterRpi3.img.xz ./2017-11-12-debianBusterRpi3.img

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,64 bits,12 CPUs Intel(R) Xeon(R) CPU           W3680  @ 3.33GHz (206C2),ASM,AES-NI)

Scanning the drive:
1 file, 7549747200 bytes (7200 MiB)

Creating archive: 2017-11-12-debianBusterRpi3.img.xz

Items to compress: 1


Files read from disk: 1
Archive size: 1802331200 bytes (1719 MiB)
Everything is Ok

As I like very much this message we'll finish on this ;-).


Webography

  1. Main Site Raspberry Pi
  2. Image Creation Scripts
  3. RaspberryPi kernel source
  4. Short presentation of the images
  5. archlinux manual
  6. mraa software
  7. Upm software
  8. Debian Live Image
  9. How to create a Debian bootable USB key

Commentaires